package com.canqiang.docadvice;

import java.util.ArrayList;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseExpandableListAdapter;
import android.widget.TextView;

public class PatientInCourseListAdapter extends BaseExpandableListAdapter  {
	private Context context;
	private ArrayList<String> group;
	private ArrayList<ArrayList<PatientInCourseList>> child;
	private LayoutInflater inflater;
	public PatientInCourseListAdapter(Context context, ArrayList<String> group,
			ArrayList<ArrayList<PatientInCourseList>> child) {
		this.context=context;
		this.group=group;
		this.child=child;
		this.inflater = LayoutInflater.from(context);
	}
	@Override
	public Object getChild(int arg0, int arg1) {
		// TODO Auto-generated method stub
		return child.get(arg0).get(arg1);
	}
	@Override
	public long getChildId(int arg0, int arg1) {
		// TODO Auto-generated method stub
		return (long)(arg0*1024+arg1);
	}
	@Override
	public View getChildView(int groupPosition, int childPosition, boolean isLastChild, View convertView,
			ViewGroup parent) {
		// TODO Auto-generated method stub
		View v=null;
		if( convertView != null )
            v = convertView;
        else
        	v = inflater.inflate(R.layout.patientincoursechild,parent,false);
		PatientInCourseList l=(PatientInCourseList)getChild(groupPosition,childPosition);
		TextView t=(TextView) v.findViewById(R.picourse.child);
		t.setText(l.getIntime());
		return v;
	}
	@Override
	public int getChildrenCount(int arg0) {
		// TODO Auto-generated method stub
		return child.get(arg0).size();
	}
	@Override
	public Object getGroup(int arg0) {
		// TODO Auto-generated method stub
		return group.get(arg0);
	}
	@Override
	public int getGroupCount() {
		// TODO Auto-generated method stub
		return group.size();
	}
	@Override
	public long getGroupId(int arg0) {
		// TODO Auto-generated method stub
		return (long)(arg0*1024);
	}
	@Override
	public View getGroupView(int groupPosition, boolean isExpanded, View convertView, ViewGroup parent) {
		// TODO Auto-generated method stub
		View v=null;
		if( convertView != null )
            v = convertView;
        else
        	v = inflater.inflate(R.layout.patientincoursegroup,parent, false);
		String g=(String)getGroup(groupPosition);
		TextView gt=(TextView) v.findViewById(R.picourse.group);
		gt.setText(g);
		return v;
	}
	@Override
	public boolean hasStableIds() {
		// TODO Auto-generated method stub
		return true;
	}
	@Override
	public boolean isChildSelectable(int arg0, int arg1) {
		// TODO Auto-generated method stub
		return true;
	}
	public void onGroupCollapsed (int groupPosition) {} 
    public void onGroupExpanded(int groupPosition) {}

}
